﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStringListModel>
#include <QStandardItemModel>
#include <QtWebEngineWidgets>
#include "hwebview.h"


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->splitter_3->setStretchFactor(0, 1);
    ui->splitter_3->setStretchFactor(1, 8);
    ui->splitter_2->setStretchFactor(0, 3);
    ui->splitter_2->setStretchFactor(1, 8);
    ui->splitter->setStretchFactor(0, 8);
    ui->splitter->setStretchFactor(1, 2);


    //向listview添加模拟数据

    QStringList mockData;
    mockData <<"first"<<"second"<<"third";
    QStringListModel * model = new QStringListModel(mockData);
    ui->listView->setModel(model);

    //向table view添加模拟数据
    QStandardItemModel  *tablemodel = new QStandardItemModel();
    tablemodel->setColumnCount(4);
    tablemodel->setHeaderData(0,Qt::Horizontal,QString::fromLocal8Bit ("序号"));
    tablemodel->setHeaderData(1,Qt::Horizontal,QString::fromLocal8Bit ("ID"));
    tablemodel->setHeaderData(2,Qt::Horizontal,QString::fromLocal8Bit ("名称"));
    tablemodel->setHeaderData(3,Qt::Horizontal,QString::fromLocal8Bit ("类型"));

    ui->tableView_2->setModel(tablemodel);
    //表头信息显示居左
    ui->tableView_2->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
    //设置列宽不可变
    //ui->tableView->horizontalHeader()->setResizeMode(0,QHeaderView::Fixed);
    //ui->tableView->horizontalHeader()->setResizeMode(1,QHeaderView::Fixed);
    ui->tableView_2->setColumnWidth(0,80);
    ui->tableView_2->setColumnWidth(1,80);
    ui->tableView_2->setColumnWidth(2,80);
    ui->tableView_2->setColumnWidth(3,80);

    //三、添加行（添加三行一样的信息）：
     for(int i = 0; i < 3; i++)
     {
         tablemodel->setItem(i,0,new QStandardItem("2009441676"));
            //设置字符颜色
         tablemodel->item(i,0)->setForeground(QBrush(QColor(255, 0, 0)));
            //设置字符位置
         tablemodel->item(i,0)->setTextAlignment(Qt::AlignCenter);

         tablemodel->setItem(i,1,new QStandardItem(QString::fromLocal8Bit("啊")));
         tablemodel->setItem(i,2,new QStandardItem(QString::fromLocal8Bit("哈哈")));
         tablemodel->setItem(i,3,new QStandardItem(QString::fromLocal8Bit("哈哈哈")));

     }
     //x是指定删除哪一行
     //tablemodel->removeRow(x);
     //删除所有行
     //tablemodel->removeRows(0,model->rowCount());

     HWebView * view = new HWebView();
     view->setUrl(QUrl("https://www.amap.com/"));
     //view->show();


     QHBoxLayout *hbox = new QHBoxLayout();
     hbox->addWidget(view);

     ui->groupBox->setLayout(hbox);


}

MainWindow::~MainWindow()
{
    delete ui;
}
